//获取角色
var utype=JSON.parse(localStorage.getItem('usertype'))
var uinfo=JSON.parse(localStorage.getItem('userInfo'))
var tourl={}
var tel=uinfo.mtel
$.each(utype, function(k,v) {
	switch (v){
		case 'lawyer':
		    tourl['lawyer']='schedule_manage/getScheduleList'
			break;
	    case 'lawyer-admin':
            tourl['law']='schedule_manage/getScheduleList'
            break;
		case 'adult-admin':
		    tourl['adult']='schedule_manage/getScheduleList'
            break;
        case 'psyer':
            tourl[v]='Psy_Record_Manage/getAppointList'
            break;
        case 'psyer-admin':
            tourl['psy']='schedule_manage/getScheduleList'
            break;
        case 'survey':
            tourl['police']='schedule_manage/getScheduleList'
            break;
        case 'survey-admin':
            tourl['survey']='schedule_manage/getScheduleList'
            break;
        case 'protector':
            tourl[v]='Guard_Record_Manage/guardList'
            break;
		default:
			break;
	}
});


/******************渲染数据**************/
$(function(){
    var waitingDialog
    mui.plusReady(function(){
        waitingDialog = plus.nativeUI.showWaiting("提交中");
    })
    $.each(tourl,function(k,v){
        var getDodata={
            url:v,
            fromwho:'ld',
            sendData:{
                p:'',
                type:k,
                tel:tel
            }
        };
        console.log(getDodata.sendData.type)
        getAjaxSyn(getDodata,
            function(data){
                if(data.result==1){
                    var curData=data.data
                    if(k=='psyer'){
                        setPsyList(curData)
                        return false;
                    }
                    if(k=='protector'){
                        setProList(curData)
                        return false;
                    }
                    setDoList(curData)
                }
            },
            function(data){
                console.log(data.msg)
            }
        )
    })
    mui.plusReady(function(){
        waitingDialog.close();
    })
})
    
    
    //获取数据
    
    //渲染数据
    function setDoList(curData){
        var alredyData=''
        var unData=''
        $.each(curData,function(k,v){
            if(v.status=='未办理'){
                unData=`
                        <li class="nbaOne" data-id="${v.base_msg_id}" id="${v.apply_id}" data-type="${v.type_o}">
                            <p class="ajbh">案件编号：${v.num}</p>
                            <p class="dbsq">待办事情：${v.type}</p>
                            <p class="fqsj">发起时间：${timeDate(v.create_time*1000)}</p>
                        </li>
                `
                $('#item1 ul').append(unData)
            }else{
                alredyData=`
                        <li class="nbaOne" data-id="${v.base_msg_id}" id="${v.apply_id}" data-type="${v.type_o}">
                            <p class="ajbh">案件编号：${v.num}</p>
                            <p class="dbsq">待办事情：${v.type}</p>
                            <p class="fqsj">发起时间：${timeDate(v.create_time*1000)}</p>
                        </li>
                `
                $('#item2 ul').append(alredyData)
            }
        })
    }
    function setPsyList(curData){
        var alredyData=''
        var unData=''
        $.each(curData,function(k,v){
            if(v.status=='未处理'){
                unData+=`
                        <li class="nbaOne" data-id="${v.base_msg_id}" id="${v.id}" data-type="psyer">
                            <p class="ajbh">案件编号：${v.human_num}</p>
                            <p class="dbsq">指派内容：${v.content}</p>
                            <p class="fqsj">发起时间：${v.add_time}</p>
                        </li>
                `
                $('#item1 ul').append(unData)
            }else{
                alredyData+=`
                        <li class="nbaOne" data-id="${v.base_msg_id}" id="${v.id}" data-type="psyer">
                            <p class="ajbh">案件编号：${v.human_num}</p>
                            <p class="dbsq">指派内容：${v.content}</p>
                            <p class="fqsj">发起时间：${v.add_time}</p>
                        </li>
                `
                $('#item2 ul').append(alredyData)
            }
        })
    }
    function setProList(curData){
        var alredyData=''
        var unData=''
        $.each(curData,function(k,v){
            var type_ch
            switch (v.type){
            	case 'record':
            	   type_ch='观护记录'
            		break;
                case 'evaluate':
                   type_ch='综合考评'
                    break;
                case 'labour':
                   type_ch='劳动改造'
                    break;
                case 'thought':
                   type_ch='思想汇报'
                    break;
            	default:
            		break;
            }
            if(v.status==0){
                unData=`
                        <li class="nbaOne" data-id="${v.base_msg_id}" id="${v.id}" data-type="protector">
                            <p class="ajbh">观护人编号：${v.guarded_num}</p>
                            <p class="dbsq">观护类型：${type_ch}</p>
                            <p class="fqsj">发起时间：${timeDate(v.create_time*1000)}</p>
                        </li>
                `
                $('#item1 ul').append(unData)
            }else{
                alredyData=`
                        <li class="nbaOne" data-id="${v.base_msg_id}" id="${v.id}" data-type="protector">
                            <p class="ajbh">观护人编号：${v.guarded_num}</p>
                            <p class="dbsq">观护类型：${type_ch}</p>
                            <p class="fqsj">发起时间：${timeDate(v.create_time*1000)}</p>
                        </li>
                `
                $('#item2 ul').append(alredyData)
            }
        })
    }
/******************渲染数据end**************/


/******************跳转**************/
mui(".mui-content").on('tap','.nbaOne',function(){
    var cid=$(this).attr('data-id')
    var aid=$(this).attr('id')
    var type=$(this).data('type')
    mui.openWindow({
        url:`business.html?cid=${cid}&aid=${aid}&type=${type}`,
    });
})
/******************跳转end**************/